package org.micro.frame.mybatis.plus.configuration;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.sql.Timestamp;

/**
 * The Micro Meta Object Handler
 *
 * @author lry
 */
public class MicroMetaObjectHandler extends MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());

        //setter create time
        super.setFieldValByName(SpecialFieldEnum.CREATE_TIME.getField(), timestamp, metaObject);
        //setter delete flag
        super.setFieldValByName(SpecialFieldEnum.DELETE_FLAG.getField(), SpecialFieldEnum.DELETE_FLAG.getObject(), metaObject);

        //setter chang time
        super.setFieldValByName(SpecialFieldEnum.CHANG_TIME.getField(), timestamp, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());

        //setter chang time
        super.setFieldValByName(SpecialFieldEnum.CHANG_TIME.getField(), timestamp, metaObject);
    }

}
